﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.IO;
using System.Diagnostics;

namespace Pet
{
    public partial class Box : Form
    {
        public Bitmap[] Resource = {
            Properties.Resources.罗小黑0,
            Properties.Resources.罗小黑1,
            Properties.Resources.罗小黑2,
            Properties.Resources.罗小黑3,
            Properties.Resources.罗小黑4,
            Properties.Resources.罗小黑5,
            Properties.Resources.罗小黑6,
            Properties.Resources.罗小黑7,
            Properties.Resources.罗小黑8,
            Properties.Resources.罗小黑9,
            Properties.Resources.罗小黑10,
            Properties.Resources.罗小黑11,
            Properties.Resources.罗小黑12,
            Properties.Resources.罗小黑13,
            Properties.Resources.罗小黑14
        };
        private Boolean IsMouseDown = false;
        private Point MousePoint;
        private Boolean hide = false;
        public Box()
        {
            InitializeComponent();
            InitMenu();
            label.Text = Helper.YiYan();
        }
        /// <summary>
        /// 初始化右键菜单
        /// </summary>
        private void InitMenu()
        {
            var munu = Helper.GetMenuSetting();
            foreach (var item in munu.Menus)
            {
                var Tsi = new ToolStripMenuItem();
                Tsi.Text = item.text;
                Tsi.Click += new EventHandler((e, r) =>
                {
                    try
                    {
                        Helper.StartProcess(item.path);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("执行失败");
                    }
                });
                toolStripMenuItem2.DropDownItems.Add(Tsi);
                //toolStripMenuItem2.DropDownItems.Add(item.text, null, (e, r) => { Helper.StartProcess(item.path); });
            }
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            //Lxh.Image = Resource[new Random().Next(0, Resource.Length)];
            int random = new Random().Next(0, 14);
            Lxh.Image = (Image)Properties.Resources.ResourceManager.GetObject($"罗小黑{random}");
            label.Text = Helper.YiYan();
        }

        private void Lxh_MouseMove(object sender, MouseEventArgs e)
        {
            if (IsMouseDown)
            {
                Point snap = Cursor.Position;
                this.Location = new Point(Location.X + (snap.X - MousePoint.X), Location.Y + (snap.Y - MousePoint.Y));
                //this.Left = Location.X + (snap.X - MousePoint.X);
                //this.Top = Location.Y + (snap.Y - MousePoint.Y);
                MousePoint = Cursor.Position;
            }
        }

        private void Lxh_MouseDown(object sender, MouseEventArgs e)
        {
            IsMouseDown = true;
            MousePoint = Cursor.Position;
        }

        private void Lxh_MouseUp(object sender, MouseEventArgs e)
        {
            IsMouseDown = false;
        }
        /// <summary>
        /// 退出程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Exists_Click(object sender, EventArgs e)
        {
            System.Environment.Exit(0);
        }
        /// <summary>
        /// 显/隐
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display(object sender, EventArgs e)
        {
            if (hide)
            {
                this.Show();
            }
            else
            {
                this.Hide();
            }
            hide = !hide;
        }
        /// <summary>
        /// 计算器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Calc(object sender, EventArgs e)
        {
            Helper.StartProcess("Calc");
        }
        /// <summary>
        /// 文件资源管理器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Explorer(object sender, EventArgs e)
        {
            Helper.StartProcess("Explorer.exe");
        }
        /// <summary>
        /// 打开根目录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RootDic(object sender, EventArgs e)
        {
            var path = Directory.GetCurrentDirectory();
            Helper.StartProcess(path);
        }
        /// <summary>
        /// 锁屏功能
        /// </summary>
        private void LockScreen()
        {
            Process.Start("rundll32.exe", "user32.dll, LockWorkStation");
        }

        private void LockScreen(object sender, EventArgs e)
        {
            LockScreen();
        }
    }
}
